package modules.lobby.data
{
	import com.netease.protobuf.UInt64;
	
	import flash.utils.Dictionary;

	public class LobbyDataModel
	{

		/**
		 * 免费桌子数据列表
		 */
		public static var freeTableData:Array = [];
		
		/**
		 * 免费桌子显示数据列表
		 */
		public static var freeTableShowData:Array = [];

		/**
		 * 免费桌子数据字典
		 **/
		public static var freeTableDic:Dictionary = new Dictionary();
		
		/**
		 * 选中的免费桌子数据
		 */
		private static var _selectedFreeTable:NormalTableModel;

		public static function set selectedFreeTable(value:NormalTableModel):void
		{
			joinRoomBtnVisble = false;

			_selectedFreeTable = value;

			selectedTableBaseUIName = "null";

			if (_selectedFreeTable != null)
			{
				selectedTableBaseUIName = "Free" + _selectedFreeTable.tableID.toString();

				joinRoomBtnVisble = true;
				joinRoomLable = 'joinRoomBtn';
			}
		}

		public static function get selectedFreeTable():NormalTableModel
		{
			return _selectedFreeTable;
		}
		
		/**
		 * 现金桌子数据列表
		 */
		public static var cashTableData:Array = [];
		
		/**
		 * 现金桌子显示数据列表
		 */
		public static var cashTableShowData:Array = [];

		/**
		 * 现金桌子数据字典
		 **/
		public static var cashTableDic:Dictionary = new Dictionary();
		
		/**
		 * 选中的现金桌子数据
		 */
		private static var _selectedCashTable:NormalTableModel;

		public static function set selectedCashTable(value:NormalTableModel):void
		{
			joinRoomBtnVisble = false;

			_selectedCashTable = value;

			selectedTableBaseUIName = "null";

			if (_selectedCashTable != null)
			{
				selectedTableBaseUIName = "Cash" + _selectedCashTable.tableID.toString();

				joinRoomBtnVisble = true;
				joinRoomLable = 'joinRoomBtn';
			}
		}

		public static function get selectedCashTable():NormalTableModel
		{
			return _selectedCashTable;
		}

		/**
		 * 加入房间按钮显示状态
		 */
		[Bindable]
		public static var joinRoomBtnVisble:Boolean = false;

		[Bindable]
		public static var joinRoomLable:String = 'joinRoomBtn';

		/**
		 * 选中列的名称
		 */
		[Bindable]
		public static var selectedTableBaseUIName:String = "null";

		/**
		 * 锦标赛数据列表
		 */
		public static var tournamentData:Array = [];

		/**
		 * 锦标赛数据字典
		 **/
		private static var tournamentDic:Dictionary = new Dictionary();

		/**
		 * 获取锦标赛信息
		 */
//		public static function getTournamentById(tournamentId:*):TournamentModel
//		{
//			if (tournamentId is UInt64)
//			{
//				if (tournamentDic[tournamentId.toString()] == null)
//				{
//					tournamentDic[tournamentId.toString()] = new TournamentModel();
//					tournamentDic[tournamentId.toString()].tournamentId = tournamentId;
//				}
//			}
//
//			return tournamentId ? tournamentDic[tournamentId.toString()] : null;
//		}

		/**
		 * 选中的现金桌子数据
		 */
//		private static var _selectedTournament:TournamentModel;

//		public static function set selectedTournament(value:TournamentModel):void
//		{
//			joinRoomBtnVisble = false;
//
//			_selectedTournament = value;
//
//			selectedTableBaseUIName = "null";
//
//			if (_selectedTournament != null)
//			{
//				joinRoomBtnVisble = true;
//
//				selectedTableBaseUIName = "Tournament" + _selectedTournament.tournamentId.toString();
//
//				if (_selectedTournament.state == TNMT_STATE_TYPE.TOURNAMENT_STATE_PLAYING)
//				{
//					joinRoomLable = 'lookonTournamentBtn';
//				}
//				else
//				{
//					joinRoomLable = 'registerTournamentBtn';
//				}
//			}
//		}
//
//		public static function get selectedTournament():TournamentModel
//		{
//			return _selectedTournament;
//		}

		/**
		 * 当前锦标赛信息界面显示的锦标赛编号
		 */
		public static var showTournamentId:UInt64;

		/**
		 * 锦标赛详细信息字典
		 **/
		private static var tournamentDetailDic:Dictionary = new Dictionary();

		/**
		 * 获取锦标赛详细信息
		 */
//		public static function getTournamentDetailById(tournamentId:*):TournamentDetailModel
//		{
//			if (tournamentId is UInt64)
//			{
//				if (tournamentDetailDic[tournamentId.toString()] == null)
//				{
//					tournamentDetailDic[tournamentId.toString()] = new TournamentDetailModel();
//					tournamentDetailDic[tournamentId.toString()].tournamentId = tournamentId;
//				}
//			}
//
//			return tournamentId ? tournamentDetailDic[tournamentId.toString()] : null;
//		}

		/**
		 * 根据桌子编号获取桌子名称
		 */
		public static function getTableNameById(tableId:*):String
		{
			if (tableId is UInt64)
			{
				tableId = tableId.toString();
			}
			var normalTableModel:NormalTableModel = cashTableDic[tableId];
			if (normalTableModel)
			{
				return normalTableModel.tableName;
			}
			return "table";
		}

		/**
		 * 获取过滤界面显示数据
		 **/
		public static function getTableFilterViewData():Object
		{
			var data:Object = {};
			var blindsData:Array = [];
			var buyInData:Array = [];

			var blindsDic:Dictionary = new Dictionary();
			var buyInDic:Dictionary = new Dictionary();

			for (var i:int = 0; i < cashTableData.length; i++)
			{
				var normalTableModel:NormalTableModel = cashTableData[i];
				blindsDic[normalTableModel.minBlinds + "/" + normalTableModel.maxBlinds] = {minBlinds: normalTableModel.minBlinds, maxBlinds: normalTableModel.maxBlinds};
				buyInDic[normalTableModel.minBuyAmount + "/" + normalTableModel.maxBuyAmount] = {minBuyAmount: normalTableModel.minBuyAmount, maxBuyAmount: normalTableModel.maxBuyAmount};
			}

			var obj:Object;
			var key:String;
			for (key in blindsDic)
			{
				obj = blindsDic[key];
				blindsData.push({label: key, data: obj});
			}
			for (key in buyInDic)
			{
				obj = buyInDic[key];
				buyInData.push({label: key, data: obj});
			}
			blindsData.sort(function(a:Object, b:Object):Number
			{
				var aPrice:Number = a.minBlinds*10000 + a.maxBlinds;
				var bPrice:Number = b.minBlinds*10000 + b.maxBlinds;
				if (aPrice > bPrice)
				{
					return 1;
				}
				else if (aPrice < bPrice)
				{
					return -1;
				}
				else
				{
					//aPrice == bPrice
					return 0;
				}
			});
			blindsData.unshift({label: "All", data: {}});
			buyInData.sort(function(a:Object, b:Object):Number
			{
				var aPrice:Number = a.minBuyAmount*10000 + a.maxBuyAmount;
				var bPrice:Number = b.minBuyAmount*10000 + b.maxBuyAmount;
				if (aPrice > bPrice)
				{
					return 1;
				}
				else if (aPrice < bPrice)
				{
					return -1;
				}
				else
				{
					//aPrice == bPrice
					return 0;
				}
			});
			buyInData.unshift({label: "All", data: {}});
			
			data.blindsData = blindsData;
			data.buyInData = buyInData;
			data.playerNumData = [{label: "All", data: 0}, {label: "0", data: 0}, {label: "1", data: 1}, {label: "2", data: 2}, {label: "3", data: 3}, {label: "4", data: 4}, {label: "5", data: 5}, {label: "6", data: 6}];
			data.cardNumData = [{label: "All", data: 0}, {label: "7", data: 7}, {label: "4", data: 4}];
			data.currencyData = [{label:"All",data:0},{label:"RMB",data:"RMB"},{label:"USD",data:"USD"},{label:"THB",data:"THB"},{label:"JPY",data:"JPY"},{label:"AUD",data:"AUD"}];
			return data;
		}
	}
}
